package test.nettys.zerocopy;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.nio.ByteBuffer;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

/**
 * @Author wangshaopeng
 * @Date 2021/8/24
 */
public class NewServer {

    public static void main(String[] args) throws IOException {

        InetSocketAddress address = new InetSocketAddress(8899);
        ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
        ServerSocket serverSocket = serverSocketChannel.socket();
        serverSocket.setReuseAddress(true);
        serverSocket.bind(address);

        ByteBuffer byteBuffer = ByteBuffer.allocate(4096);


        while (true){
            SocketChannel accept = serverSocketChannel.accept();
            accept.configureBlocking(true);
            int count = 0;

            while (count!=-1){
                count = accept.read(byteBuffer);
                byteBuffer.rewind();
            }
        }


    }
}
